//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __VIRTUALDEVICE_H__
#define __VIRTUALDEVICE_H__
#include <PowerDef.h>
class CVirtualDevice : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
       /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose() {}

public:
    CVirtualDevice(IInterface * pObject, unsigned long InitPowerState,
        _ELASTOS Boolean IgnoreTimer = false, _ELASTOS Boolean IgnoreControl = false);
    CVirtualDevice(_ELASTOS UInt32 DeviceID,IInterface * pObject);
    void InitDevPowerMode(_ELASTOS UInt32 mode);//rename this api later.
    void KeepSpecifiedMode(_ELASTOS UInt32 mode,_ELASTOS Boolean KeepOn);
    void SetChangeModeInterval(_ELASTOS UInt32 interval);
    ECode ChangeMode(DeviceMode mode);
    ECode ChangeMode();
    ECode SetMode(_ELASTOS UInt32 mode);
    ECode SetPowerMode(_ELASTOS UInt32 mode);
    void UpdateInputLastUse();
    void RestartTimer();
    void RestartTimer(int Interval);
    _ELASTOS UInt32 GetLeftInterval();
    ECode ChangeModeByStep();
    void SetChangeModeCallBack(TimerCallBackProc proc);
    unsigned long           PowerState;//tag
    int                     hTimer;//timer
    _ELASTOS Int32          KeepOn;
    _ELASTOS Boolean        IgnoreControl;//invoke control method will not
                                          // resume device first like usually.
    _ELASTOS Boolean        IgnoreRead;//invoke read method will not resume
                                       // input device, touch/keypad etc.
    _ELASTOS Boolean        IgnoreTimer;//when timer invoke DM_ChangeMode to
                                        // suspend device will not stop timer
                                        // the device have.
    TimerCallBackProc       ChangeModeCallBack;
    unsigned long           ModeChangeInterval;//interval between mode change,
                                               //user can change
private:
    IDeviceDriver     *     piRealdev;//physical device
    int               DeviceID;

    unsigned long    SpecifiedMode;//user can point out which mode is the
                                   // default power mode of this device.
};

#endif//__VIRTUALDEVICE_H__
